﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SingletonDemo
{
    public class Singleton5
    {
        private static Singleton5 singleton5 = null;

        private Singleton5()
        {

        }

        private static object lockObj = new object();

        public static Singleton5 Instance()
        {
            if (singleton5 == null)
            {
                lock (lockObj)
                {
                    if (singleton5 == null)
                    {
                        singleton5 = new Singleton5();
                    }
                }
            }
            return singleton5;
        }

        public void Test1()
        {
            Console.WriteLine("Test1");
        }

        public string Test2()
        {
            return "待到山花烂漫时，她在丛中笑";
        }
    }

    public class Singleton520
    {
        private static Singleton520 singleton520 = new   Singleton520();

        private Singleton520()
        {
        }

        public static Singleton520 Instance()
        {
            return singleton520;
        }

        public void Test1()
        {
            Console.WriteLine("卜算子咏梅");
        }

        public string Test2()
        {
            return "待到山花烂漫时，她在丛中笑";
        }
    }
}
